Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure Net.Download and Net.DownloadText #2904

Merged
merged 5 commits into from
Nov 20, 2019

Conversation

DasSkelett
Copy link
Member

Motivation

#2879 tried to get better insights why calls to GitHub by the bot were failing.
It was a partial success, we got the returned status code, but it also broke the custom error handling for SpaceDock for example.

Changes

First, I enabled the possibility to pass a header writeback function to CurlSharp. This allows catching the header of the response for logging purposes.
Passing it is optional.

Secondly, I created a new Kraken, NativeAndCurlDownloadFailedKraken. This one is used in both above mentioned download methods. It has some nice additions to a plain Kraken/Exception (like accessing the response (header and/or content) or the status code) and is more usable than WebExceptions.

Thirdly, I added some logging to the two download methods. If the debug-flag is set, the entire header and the content (in case of DownloadText) is written to the output. Plus, it is save in the NativeAndCurlDownloadFailedKraken, so accessing and deciding based on them higher up in the stack is easier.
Also , parsing the returned json containing a error message from SpaceDock/CurseForge now works again. This fixes a failing unit test.

Furthermore in the two last commits, I introduced two custom error messages for GitHub if the rate limit is exceeded (based on return code 403 + X-RateLimit-Remaining header),
and if CurseForge is blocking CKAN (based on return code 403).

@DasSkelett DasSkelett added Core (ckan.dll) Issues affecting the core part of CKAN Netkan Issues affecting the netkan data Network Issues affecting internet connections of CKAN labels Oct 25, 2019
Netkan/Program.cs Outdated Show resolved Hide resolved
This Kraken should be used in those cases, where we use cURL as fallback when native downloads fail.
It has some nice features: The Kraken holds the response (header + body), the uRL, the previous network exceptions and the returned status code.
Restructure Net.Download and Net.DownloadText to allow better logging and catching of download errors.
Throw `NAtiveAndCurlDownloadFailedKraken`s, as well as log more of what's happening.
@DasSkelett
Copy link
Member Author

Okay, so now it always logs the answer if the download fails, and only with debug flag if the download succeeds.
This means that @techman83 does not have to do an extra debug run to get something useful from the logs.

Copy link
Member

@HebaruSan HebaruSan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK! Let's try it.

@HebaruSan HebaruSan merged commit e9b9811 into KSP-CKAN:master Nov 20, 2019
@DasSkelett DasSkelett deleted the fix/throw-curl-errors branch November 20, 2019 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core (ckan.dll) Issues affecting the core part of CKAN Netkan Issues affecting the netkan data Network Issues affecting internet connections of CKAN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants